<template>
  <user :thisPageType="thisPageType" ref="user" :roleid="roleid" :departmentid="departmentid" :subid="subid" :id="id" />
</template>

<script>
import user from './user.vue';
export default {
  name: 'addUser',
  components: {
    user
  },
  data() {
    return {
      thisPageType: '',
      departmentid: '',
      subid: '',
      id: '',
      randomNum: '',
      roleid: ''
    };
  },
  methods: {
    setNotice() {
      this.thisPageType = this.$route.query.type;
      this.departmentid = this.$route.query.departmentid;
      this.subid = this.$route.query.subid;
      this.id = this.$route.query.id;
      this.roleid = this.$route.query.roleid;
      this.$nextTick(() => {
        this.$refs.user.getRoleList();
      });
    }
  },
  created() {
    this.subid = this.$route.query.subid;
  },
  activated() { // 路由随机数 防止重复代码
    if (this.$route.query.randomNum) {
      if (this.randomNum == '') { // 第一次创建
        this.randomNum = this.$route.query.randomNum;
        this.setNotice();
      } else if (this.randomNum == this.$route.query.randomNum) { // 仅仅是切换过来
        return false;
      } else if (this.randomNum !== this.$route.query.randomNum) { // 又进行了其他操作
        this.randomNum = this.$route.query.randomNum;
        this.setNotice();
      }
    } else {
      return;
    }
  }
};
</script>

<style>
</style>